package mht.practice.ListNode;

/**
 * Created by MHT on 2017/9/15.
 */
public class getListLength {

    public static int getListLength(ListNode head) {
        // 注意头结点为空情况
        if (head == null) {
            return 0;
        }

        int len = 0;
        ListNode cur = head;
        while (cur != null) {
            len++;
            cur = cur.next;
        }
        return len;
    }
}
